<template>
	<view class="gui-bg-gray">
		<view class="gui-padding gui-rows gui-space-between gui-align-items-center gui-bg-white gui-text-center"
			style="padding: 30rpx;">
			<text class="gui-h3 product-name gui-color-blue"
				style="text-align: center;margin: auto;">{{product.cate ? product.cate.name : "--"}}</text>
			<view class="">
				<text class="gui-h4 product-name gui-color-blue"
					style="text-align: center;margin: auto;">{{product.category_name}}</text>
			</view>
		</view>

		<view class="gui-padding gui-bg-white toubu" style="padding: 20rpx;text-indent: 2em;margin-top: 10rpx;">
			<!-- <text>固定数据</text> -->
			<view class="gui-text">
				<text>申请单编号 : {{product.id}}</text>
			</view>
			<view class="gui-text">
				<text>创建时间 : {{product.created_at}}</text>
			</view>
			<view class="gui-text">
				<text>申请项目 : {{product.category_name}}</text>
			</view>
			<view class="gui-text">
				<text>创建人编号 : {{product.create_member}}</text>
			</view>
			<view class="gui-text">
				<text>在职状态 : {{product.work_status}}</text>
			</view>
			<view class="gui-text">
				<text>厂牌号 : {{product.user_bh}}</text>
			</view>
			<view class="gui-text">
				<text>申请人 : {{product.member}}</text>
			</view>
			<view class="gui-text">
				<text>性别 : {{product.sex}}</text>
			</view>
			<!-- <view class="gui-text">
					<text>身份证 : {{product.sfz}}</text>
				</view> -->
			<view class="gui-text">
				<text>所在工会 : {{product.lessee}}</text>
			</view>
		</view>

		<!-- <text>分类数据</text> -->
		<view class="gui-padding gui-bg-white"
			style="padding: 20rpx;text-indent: 2em;margin-top: 10rpx; display: flex; align-items: center;">
			<view class="gui-text gui-color-blue" style="font-size: 30rpx;">所选分类数据</view>
			<view class="gui-text" style="font-size: 30rpx;" v-for="(item,index) in product.category_data" :key="index">
				<text>{{index ? index : ""}} : {{item}}</text>
			</view>
		</view>

		<view class="gui-padding gui-bg-white" style="padding: 20rpx;text-indent: 2em;margin-top: 10rpx;">
			<view class="gui-text" style="font-size: 30rpx; margin: 10rpx 0;" v-for="(item,index) in form_data"
				:key="index">
				<text v-if="index == 'phone'">手机号码' : {{item}}</text>
				<text v-else-if="index == 'transfer'">转款账号 : {{item}}</text>
				<text v-else-if="index == 'transfer_addr'">账户开户行 : {{item}}</text>
				<text v-else>{{index}} : {{item}}</text>
			</view>
		</view>

		<view class="gui-padding gui-margin-top gui-bg-white">
			<text class="gui-h4">审批进程 : </text>
			<view class="gui-border-b" v-for="(item,index3) in product.process" :key="index3">
				<view style="padding: 8rpx;"
					:style="{'margin-top': '30rpx','border':item.is_approver == '1' ? 'red solid 1rpx' : ''}">
					<text
						:class="item.approver_status == '1' ? item.is_approver == '1' ? 'gui-h5 gui-color-red' : 'gui-h5 gui-color-green' : item.is_approver == '1' ? 'gui-h5 gui-color-red' : 'gui-h5'">{{item.approver_status == '1' ? item.is_approver == '1' ? "不通过":"已审" : item.is_approver == '1' ? "正审" : "待审"}}</text>
					<text class="gui-h5" style="margin-left: 30rpx;">
						{{item.approver_name}} - {{item.approver_member}}</text>
				</view>
				<view class="" style="margin-top: 10rpx;" v-if="item.approver_opinion">
					<text class="" style="">审批意见 : {{item.approver_opinion}}</text>
				</view>
				<view class="" style="margin-top: 10rpx;" v-if="item.send_presents">
					<text class="" style="">慰问品 : {{item.send_presents}}</text>
				</view>
				<view v-if="item.approver_name == '工会干事' && item.thumb"
					style="display: flex; flex-wrap: wrap; align-items: center;margin-top: 10rpx; ">
					<view class="" style="margin-right: 15rpx;">慰问品领取单 :</view>
					<view v-for="(item1,index1) in item.thumb"
						style="width: 150rpx; height: 100rpx; border-radius: 20rpx; margin: 5rpx 10rpx;" :key="index1">
						<image @tap="show_img(item1)" style="width: 100%; height: 100%;" :src="item1" mode="">
						</image>
					</view>
				</view>
				<view class="" style="margin-top: 10rpx;" v-if="item.ps">
					<text class="" style="">审批金额 : {{item.ps}}</text>
				</view>
				<view class="" style="margin-top: 10rpx;">
					<text class="gui-h5" style="">{{item.approver_status == '1' ? item.updated_at : ""}}</text>
				</view>
			</view>
		</view>

		<view class="gui-padding gui-margin-top gui-bg-white" style="padding: 30rpx;">
			<text class="gui-h4">附件信息 : </text>
			<view class="gui-margin-top gui-text-center" v-for="(item,index2) in product.category" :key="index2">
				<text class="gui-h3 gui-color-red">{{item.name}}</text>
				<view class="" v-for="(img_item,img_index) in item.path.split(',')" :key="img_index">
					<image v-if="img_item" :src="img_item" mode="widthFix" style="" @tap="img_show(img_item)">
					</image>
					<text v-else class="gui-text-center gui-color-gray">待上传</text>
				</view>
			</view>
		</view>

		<!-- 底部 -->
		<view class="product-footer gui-bg-white gui-border-t">
			<!-- 底部按钮栏 -->
			<view style="display: flex; align-items: center; height: 95rpx;">
				<view style="width: 20%;" @tap="goHome">
					<view style="width: 42rpx; height: 46rpx; margin: 0 auto; padding-top: 8rpx;">
						<image style="width: 100%; height: 100%;" src="@/static/activity/apply/menu_imgs/home.png">
						</image>
					</view>
					<view style="font-size: 20rpx; text-align: center;">首页</view>
				</view>
				<view @tap="sh_open"
					style="width: 78%; background-image: linear-gradient(to right, #E86E36, #EB5057); text-align: center; color: white; height: 78rpx; line-height: 78rpx;">
					审核</view>
			</view>
		</view>

		<!-- 居中弹出 -->
		<gui-popup ref="guipopup1">
			<view class="gui-relative gui-box-shadow gui-bg-white" style="padding: 20rpx;">
				<!-- <gui-image src="https://cmsuse.oss-cn-beijing.aliyuncs.com/g5/16.png" :width="580"></gui-image> -->
				<text class="gui-text gui-h6" style=""><button class="gui-bg-red gui-color-white"
						@tap="show_big">{{big_tip}}</button></text>
				<view v-if="formData.qm" class="gui-bg-gray qianming">
					<image style="width: 100%; height: 100%;" :src="formData.qm" mode="widthFix"></image>
				</view>
				<!-- <view v-else class="gui-margin-top gui-bg-gray"
					:style="{height:canvas.height+'rpx', overflow:'hidden'}">
					<canvas id="graceSign" canvas-id="graceSign" @touchstart="tstart" @touchmove="tmove"
						:style="{width:canvas.width+'rpx', height:canvas.height+'rpx'}"></canvas>
				</view> -->
				<view class="gui-margin-top gui-flex gui-rows gui-space-between" v-if="!isNew">
					<text class="sign-btn gui-text gui-color-gray gui-block-text" @tap="canvasInit">重新签名</text>
					<text class="sign-btn gui-text gui-color-blue gui-block-text" @tap="upload_qm_img">提交签名</text>
				</view>

				<view class="" style="margin-top: 30rpx;">
					<radio-group @change="radioChange" class="gui-flex">
						<view class="">
							<radio value="0" :checked="is_radio === 0" /><text>不通过</text>
						</view>
						<view class="" style="margin-left: 20rpx;">
							<radio value="1" :checked="is_radio === 1" /><text>通过</text>
						</view>
					</radio-group>
				</view>

				<view class="gui-form-item gui-border-b"
					v-if="product.is_sh && product.this_approval.is_opinion != '0'">
					<text class="gui-form-label">审核意见 : </text>
					<view class="gui-form-body">
						<input :adjust-position="true" type="text" class="gui-form-input"
							v-model="formData.approver_opinion" name="opinion" @input="inputting"
							placeholder="请输入审核意见" />
					</view>
					<text class="gui-form-icon gui-icons gui-text-center gui-color-gray"
						v-if="formData.approver_opinion.length >= 1" @click="clear_opinion">&#xe78a;</text>
				</view>

				<view v-if="whether_location == 'yes'">
					<view style="display: flex; align-items: center;" class="gui-border-b"
						v-if="form_data.是否柳州市城区内住院 == '是'">
						<view class="gui-form-label">慰问品 : </view>
						<uni-data-checkbox v-model="p_index" :localdata="presents"
							@change="send_presents"></uni-data-checkbox>
					</view>
				</view>

				<!-- <view v-if="whether_location == 'yes'">
					<view style="padding-bottom: 50rpx;" class="gui-border-b" v-if="form_data.是否柳州市城区内住院 == '是'">
						<view style="font-size: 30rpx; margin-top: 20rpx;">慰问品领取单 :</view>
						<view style="display: flex; flex-wrap: wrap;">
							<view class="" v-for="(item,index) in formData.imgs"
								style="width: 150rpx; height: 100rpx; border-radius: 20rpx; margin: 15rpx 0 0 20rpx;"
								:key="index">
								<image style="width: 100%; height: 100%;" :src="item" mode="">
								</image>
								<view style="text-align: center;" @click="dele_file_img(index)">删除</view>
							</view>
							<view @tap="upload_img" class="gui-h1 gui-color-gray" v-if="formData.imgs.length < 3"
								style="width: 100rpx; height: 100rpx; background-color: #e7e7e7; text-align: center; border-radius: 20rpx; margin: 15rpx 0 0 20rpx;">
								<text style="line-height: 90rpx;">+</text>
							</view>
						</view>

					</view>
				</view> -->

				<view class="gui-form-item gui-border-b" v-if="is_radio2 == '1'">
					<text class="gui-form-label">审核金额 : </text>
					<view class="gui-form-body" v-if="forbid == true">
						<input :adjust-position="true" type="text" class="gui-form-input" v-model="formData.ps"
							name="ps" @input="inputting" placeholder="请输入审核金额" />
					</view>
					<view class="gui-form-body" v-if="forbid == false">
						<input :disabled="true" :adjust-position="true" type="text" class="gui-form-input"
							v-model="formData.ps" name="ps" @input="inputting" placeholder="请输入审核金额" />
					</view>
				</view>

				<view class="gui-form-item gui-border-b gui-bg-gray" v-if="back_opinion">
					<text class="gui-form-label">上级意见 : </text>
					<view class="gui-form-body">
						<text class="gui-color-red">{{back_opinion}}</text>
					</view>
				</view>

				<!-- <view class="gui-margin-top gui-form-item gui-border-b gui-bg-gray" v-if="ps_data">
						<text class="gui-form-label">上级核审 : </text>
						<view class="gui-form-body">
							<text class="gui-color-red">{{ps_data}}</text>
						</view>
					</view> -->

				<!-- <view class="gui-margin-top">
					<radio-group @change="radioChange2" class="gui-flex">
						<view class="">
							<text>是否金额转中文大写</text>
						</view>
						<view class="">
							<radio value="0" :checked="is_radio2 === 0" /><text>否</text>
						</view>
						<view class="" style="margin-left: 20rpx;">
							<radio value="1" :checked="is_radio2 === 1" /><text>是</text>
						</view>
					</radio-group>
				</view> -->

				<view class="gui-margin-top gui-text-center" v-if="tip_text">
					<text class="gui-color-red">{{tip_text}}</text>
				</view>

				<view class="gui-margin-top">
					<button class="gui-bg-blue gui-color-white" style="" @tap="sh_sumbit">确认审核</button>
				</view>


				<!-- 关闭按钮 -->
				<text class="gui-block-text demo-close gui-icons gui-color-white gui-absolute-rt"
					@tap.stop="close1">&#xe78a;</text>
			</view>
		</gui-popup>


		<!-- 居中弹出(签名板) -->
		<gui-popup ref="guipopup2" :width="'100%'">
			<view class="gui-relative gui-box-shadow gui-bg-white" style="padding: 30rpx;height: 1280rpx;">
				<!-- <gui-image src="https://cmsuse.oss-cn-beijing.aliyuncs.com/g5/16.png" :width="580"></gui-image> -->
				<text class="gui-text gui-color-red gui-h6" style="">注 :
					请横屏书写,提交上传之后会自动处理,上传完成后点击确认签名即可看到效果</text>

				<view class="gui-margin-top gui-bg-gray"
					:style="{height:'900rpx', overflow:'hidden',transform:big_rotate}">
					<canvas id="graceSign2" canvas-id="graceSign2" @touchstart="tstart" @touchmove="tmove"
						:style="{width:canvas.width+'rpx', height:'900rpx'}"></canvas>
				</view>
				<view class="gui-margin-top gui-flex gui-rows gui-space-between" v-if="!isNew2">
					<text class="sign-btn gui-text gui-color-gray gui-block-text" @tap="canvasInit">重新签名</text>
					<text class="sign-btn gui-text gui-color-blue gui-block-text" @tap="upload_qm_img">提交签名</text>
				</view>

				<view class="gui-margin-top gui-text-center" v-if="tip_text">
					<text class="gui-color-red">{{tip_text}}</text>
				</view>

				<view class="gui-margin-top">
					<button class="gui-bg-blue gui-color-white" style="" @tap="big_qr_qm">确认签名</button>
				</view>


				<!-- 关闭按钮 -->
				<text class="gui-block-text demo-close gui-icons gui-color-white gui-absolute-rt"
					@tap.stop="close1">&#xe78a;</text>
			</view>
		</gui-popup>

		<view class=""><!-- 遮盖层 -->
			<gui-page-loading ref="guipageloading"></gui-page-loading>
		</view>

		<!-- 底部占位 -->
		<view style="height:120rpx;"></view>
	</view>
</template>
<script>
	var graceJS = require('@/Grace6/js/grace.js');
	var parserHtml = require("@/Grace6/js/parserHTML.js");
	export default {
		data() {
			return {
				// 轮播图 
				// swiperItems: [{
				// 	img: 'https://cmsuse.oss-cn-beijing.aliyuncs.com/g5/1.png',
				// 	url: '',
				// 	// opentype : 'navigate'
				// }],
				// 商品信息
				product: {},
				form_data: {},
				// 切换索引
				active: 0,
				// 属性选择
				attrShow: false,

				id: 0,
				user: null,
				comm_pl: '',
				news: [],

				//是否大屏
				is_big: false,
				big_rotate: 'rotate(0deg)', //旋转角度
				ctx2: null, // 画布对象,
				drawTimer2: null, // 演示存储计算器,
				isNew2: true, // 画布是否是空白的

				//签名
				canvas: {
					width: 690, // 画布宽度，单位 rpx
					height: 380, // 画布高度, 单位 rpx
					bgColor: '#F6F7F8', // 画布演示
					textColor: '#000000', // 画笔颜色
					widthIn: 300, // 自动计算转换为 px
					heightIn: 300, // 自动计算转换为 px
					size: 3, // 画笔粗细
				},
				ctx: null, // 画布对象,
				drawTimer: null, // 演示存储计算器,
				isNew: true, // 画布是否是空白的

				qm_img: '', //签名base64

				is_radio: 1, //是否通过
				formData: {
					'approver_opinion': '',
					'is_radio': 1,
					'qm': null,
					'is_number': 0,
					'a_id': 0,
					'imgs': [],
				},
				apply: [21, 11, 121],
				is_radio2: 0, //是否数字转中文
				tip_text: '', //提交提示文本
				big_tip: '请点击签名',
				ps_data: '', //附加数据
				back_opinion: '', //上级意见
				whether_location: null, //会员住院-工会干事(需要增加审批弹窗内容)
				p_index: -1,
				presents: [],
				imgs: [],
				forbid: true, // 是否可填写金额
			}
		},
		onLoad(option) {
			// console.log('option: ', option);
			this.id = option.id;
			this.user = uni.getStorageSync("member");
		},
		onReady() {
			this.show_data(this.id);
			this.canvasInit();
		},
		methods: {
			send_presents(e) {
				// 选择慰问品套餐
				// console.log('e:', e.detail.data.value);
				this.formData.send_presents = e.detail.data.text
				this.formData.ps = e.detail.data.text
			},
			big_qr_qm() { //大屏确认签名
				if (this.formData.qm == null) {
					this.tip_text = "请先提交签名后再确认";
				} else {
					this.close2();
					this.is_big = true;
					this.big_tip = "重新生成";
					// this.big_rotate = 'rotate(0deg)';
					this.saveImg2();
				}
			},
			show_big() { //显示大屏
				this.open2();
				this.is_big = true;
				this.big_tip = "重新生成";
				this.big_rotate = 'rotate(0deg)';
				this.canvasInit();
			},
			sh_sumbit() { //确认审核
				let self = this;
				if (this.formData.approver_opinion == '' && this.product.this_approval.is_opinion != '0') {
					// uni.showToast({title:self.is_radio2 == '1' ? '请输入审核金额' : '请输入审核意见',icon:'none'});
					self.tip_text = '请输入审核意见';
					return;
				}
				// 慰问品改为不必填项，注释掉验证
				// if (this.whether_location == 'yes' && this.formData.send_presents == null) {
				// 	self.tip_text = '请选择慰问品';
				// 	return;
				// }
				// 慰问品领取单也改为不必填项，注释掉验证
				// if (this.whether_location == 'yes' && this.formData.imgs <= 0) {
				// 	self.tip_text = '请添加慰问品领取单';
				// 	return;
				// }
				if (!this.formData.ps && self.is_radio2 == '1') {
					self.tip_text = '请输入审核金额';
					return;
				}
				if (this.formData.qm == '') {
					// uni.showToast({title:'请输入审核意见'});
					self.tip_text = '请 书写签名，并 提交签名';
					return;
				}
				this.formData.a_id = this.id;
				this.formData.is_sh = this.product.is_sh;
				console.log(this.formData, 'formData');

				this.$refs.guipageloading.open();

				// if (this.product.this_approval.is_number) { //附加
				// 	self.formData.ps = self.formData.approver_opinion;
				// } else {
				// 	self.formData.ps = self.ps_data;
				// }

				let url = '/hzj_apply/approvers_sh'
				// let parm = {
				// 	self.formData
				// }
				self.$boya.NPost(url, self.formData, function(res) {
					self.$refs.guipageloading.close();
					if (res.code == 200) {
						self.close1();
						uni.showModal({
							title: '提示',
							content: res.data ? res.data : "操作成功",
							// showCancel: false,
							// success: function(res) {
							// 	if (res.confirm) {
							// 		uni.navigateBack()
							// 	}
							// }
						});
						self.show_data(self.id);
					} else {
						self.tip_text = "操作失败,请重试,或检查数据";
					}
					console.log('shhhhhhhhh: ', res);
				})


				// self.grace.post(self.apiUrl + "/hzj_apply/approvers_sh", self.formData, function(res) {
				// 	self.$refs.guipageloading.close();
				// 	if (res.code == 200) {
				// 		self.close1();
				// 		uni.showModal({
				// 			title: '提示',
				// 			content: res.data ? res.data : "操作成功",
				// 		});
				// 		self.show_data(self.id);
				// 	} else {
				// 		self.tip_text = "操作失败,请重试,或检查数据";
				// 	}
				// 	console.log('shhhhhhhhh: ', res);
				// });

			},
			// set_document() {
			// 	let self = this
			// 	// console.log('我我我我我我我');
			// 	self.grace.post(self.apiUrl + "/hzj_apply/generate", {
			// 		apply: self.apply
			// 	}, function(res) {
			// 		console.log(res, 'generate');
			// 		self.$refs.guipageloading.close();
			// 		if (res.code == 200) {
			// 			// self.file_path = res.data;
			// 			self.tip('1', '生成成功');
			// 			self.show_data(self.id);
			// 		} else {
			// 			self.tip('0', res.data);
			// 		}
			// 	});
			// },
			// 清空输入框的值
			clear_opinion() {
				this.formData.approver_opinion = '';
			},
			// 监听输入框输入事件
			inputting: function(e) {
				var name2Val = e.detail.value;
				console.log(name2Val, 'name2Val');
			},
			radioChange(evt) { //单选切换
				console.log('evt： ', evt.detail.value);
				this.is_radio = evt.detail.value;
				this.formData.is_radio = evt.detail.value;
				if (evt.detail.value == 0) {
					this.p_index = '-1'
					this.formData.ps = '0元'
					this.forbid = false
					this.whether_location = null
				} else {
					this.forbid = true
					this.formData.ps = null
					if (this.product.this_approval.name == '工会干事' && this.form_data.是否柳州市城区内住院 == '是') {
						this.whether_location = 'yes'
					}
				}
			},
			radioChange2(evt) { //单选切换
				this.is_radio2 = evt.detail.value;
				this.formData.is_number = evt.detail.value;
			},
			upload_qm_img() { //上传签名
				let self = this;
				if (this.qm_img) {
					let is_rotate = 0;
					if (self.is_big) { //大屏旋转处理
						// self.big_rotate = 'rotate(-90deg)';
						// self.ctx2.rotate(45 * Math.PI/180);
						// self.ctx.translate(300,300);
						// console.log('旋转');
						// self.saveImg2();
						is_rotate = 1;
					}
					self.$refs.guipageloading.open();

					uni.uploadFile({
						url: self.apiUrl + "/hzj_apply/upload_huaweicloud_obs",
						filePath: self.qm_img,
						name: 'file',
						success: (up_res) => {
							self.$refs.guipageloading.close();

							let upload_res = JSON.parse(up_res.data);
							if (upload_res.code == 200) {
								self.tip_text = "签名上传成功";
								self.formData.qm = upload_res.data.url;
							} else {
								self.tip_text = "签名上传失败,请重试";
							}
							console.log('up_res.data.url: ', upload_res);
						}
					});

					// // let url = '/public/localhost_up_base64'
					// let url = '/hzj_apply/upload_huaweicloud_obs'
					// let parm = {
					// 	pathName: self.user.id + self.user.name + '.png',
					// 	tmppath: this.qm_img,
					// 	file: this.qm_img,
					// 	is_rotate: is_rotate
					// }
					// self.$boya.NPost(url, parm, function(res) {
					// 	self.$refs.guipageloading.close();
					// 	if (res.code == 200) {
					// 		self.tip_text = "签名上传成功";
					// 		self.formData.qm = res.data.url;
					// 	} else {
					// 		self.tip_text = "签名上传失败,请重试";
					// 	}
					// 	console.log(res, 'upload');
					// })
				} else {
					uni.showModal({
						title: '提示',
						content: '未签名'
					});
				}
			},
			canvasInit: function() {
				setTimeout(() => {
					this.ctx = uni.createCanvasContext('graceSign');
					this.canvas.widthIn = uni.upx2px(this.canvas.width);
					this.canvas.heightIn = uni.upx2px(this.canvas.height);
					this.ctx.setFillStyle(this.canvas.bgColor);
					this.ctx.fillRect(0, 0, this.canvas.widthIn, this.canvas.heightIn);
					this.ctx.draw(true);
					this.ctx.setStrokeStyle(this.canvas.textColor);
					this.ctx.setLineWidth(this.canvas.size);
					this.isNew = true;
				}, 500);

				setTimeout(() => {
					this.ctx2 = uni.createCanvasContext('graceSign2');
					this.canvas.widthIn = uni.upx2px(this.canvas.width);
					this.canvas.heightIn = uni.upx2px(this.canvas.height);
					this.ctx2.setFillStyle(this.canvas.bgColor);
					this.ctx2.fillRect(0, 0, this.canvas.widthIn, 900);
					this.ctx2.draw(true);
					// this.ctx2.rotate(45 * Math.PI/180);
					this.ctx2.setStrokeStyle(this.canvas.textColor);
					this.ctx2.setLineWidth(this.canvas.size);
					this.isNew2 = true;
				}, 500);
			},
			tstart: function(e) {
				var x = e.touches[0].x;
				var y = e.touches[0].y;
				if (this.is_big) {
					this.ctx2.moveTo(x, y);
					this.isNew2 = false;
				} else {
					this.ctx.moveTo(x, y);
					this.isNew = false;
				}
			},
			tmove: function(e) {
				var x = e.touches[0].x;
				var y = e.touches[0].y;
				if (this.is_big) {
					this.ctx2.lineTo(x, y);
					this.ctx2.stroke();
					this.ctx2.draw(true, this.saveImg2);
					this.ctx2.moveTo(x, y);
				} else {
					this.ctx.lineTo(x, y);
					this.ctx.stroke();
					this.ctx.draw(true, this.saveImg);
					this.ctx.moveTo(x, y);
				}
			},
			// 手写完毕后自动生成一个临时图片文件
			saveImg: function() {
				let self = this;
				if (this.drawTimer != null) {
					clearTimeout(this.drawTimer);
				}
				this.drawTimer = setTimeout(() => {
					uni.canvasToTempFilePath({
						x: 0,
						y: 0,
						width: this.widthIn,
						height: this.heightIn,
						destWidth: this.widthIn,
						destHeight: this.heightIn,
						canvasId: 'graceSign',
						success: (res) => {
							// 在H5平台下，tempFilePath 为 base64
							console.log(res.tempFilePath);
							self.qm_img = res.tempFilePath;
						}
					});
				}, 200);
			},
			saveImg2: function() {
				let self = this;
				if (this.drawTimer2 != null) {
					clearTimeout(this.drawTimer2);
				}
				this.drawTimer2 = setTimeout(() => {
					uni.canvasToTempFilePath({
						x: 0,
						y: 0,
						width: this.widthIn,
						height: this.heightIn,
						destWidth: this.widthIn,
						destHeight: this.heightIn,
						canvasId: 'graceSign2',
						success: (res) => {
							// 在H5平台下，tempFilePath 为 base64
							console.log(res.tempFilePath);
							self.qm_img = res.tempFilePath;
						}
					});
				}, 200);
			},
			sh_open() { //打开审核(弹层)
				let self = this;
				console.log('product: ', self.product)
				if (self.product.is_sh == '1') {
					self.open1(); //即当前账号,已在后台判断
				} else if (self.product.is_sh) {
					//二级或劳资部等
					if (self.user.approver_lessee == self.product.is_sh) {
						self.open1();
					}
				} else {
					uni.showModal({
						title: '提示',
						content: '当前不能审核'
					});
				}
			},
			img_show(img) {
				uni.previewImage({
					urls: [img],
					index: 0
				});
			},
			//获取相应的待审核申请单
			show_data(good_id) {
				let self = this;
				console.log(good_id);
				if (good_id) {
					this.$refs.guipageloading.open();
					// 加载产品数据
					let url = '/hzj_apply/get_admin_detail'
					let parm = {
						a_id: self.id
					}
					self.$boya.NPost(url, parm, function(res) {
						self.imgs = []
						let imgs = uni.getStorageSync("imgs");
						if (imgs) {
							self.imgs = imgs
						}
						console.log('resres: ', res);
					
						if (res.data.apply.category_name == '会员住院' && res.data.apply.status == '10') {

							self.checkAndSendCoupon();
						}
						if (res.data.apply.process) {
							let process = res.data.apply.process
							for (var i = 0; i < process.length; i++) {
								// console.log('process[i]: ', process[i]);
								if (process[i].thumb) {
									let thumb = process[i].thumb.split(',')
									process[i].thumb = thumb
								}
							}
						}
						self.product = res.data.apply;
						if (res.data.apply.is_sh) {
							// if (res.data.apply.this_approval.is_number) {
							// 是否默认转大写，是否需要填写金额
							if (res.data.apply.cate.name == "医疗互助计划申请") {
								if (res.data.apply.this_approval.name == '医疗互助计划管委会') {
									self.is_radio2 = 1
								} else {
									self.is_radio2 = 0
								}
							} else if (res.data.apply.cate.name == "医疗互助计划退出") {
								if (res.data.apply.this_approval.name == '集团工会权益保障部') {
									self.is_radio2 = 1
								} else {
									self.is_radio2 = 0
								}
							} else {
								self.is_radio2 = res.data.apply.this_approval.is_number;
							}
							self.formData.is_number = res.data.apply.this_approval.is_number;
							// }

							console.log('is_radio2---------------: ', self.is_radio2);
							if (res.data.apply.this_approval.defult_op) {
								self.formData.approver_opinion = res.data.apply.this_approval.defult_op;
							} else {
								self.formData.approver_opinion = '';
							}

							for (let i = 0; i < res.data.apply.process.length; i++) {
								if (res.data.apply.process[i].is_approver == '1') {
									if (res.data.apply.process[i].solt == '1') {
										let apply_form_data = JSON.parse(res.data.apply.form_data);
										self.ps_data = apply_form_data.self_money;
									} else {
										let back_ps_data = res.data.apply.process[i - 1].ps;
										self.ps_data = back_ps_data;
										self.back_opinion = res.data.apply.process[i - 1].approver_opinion;
									}
									break;
								}
							}
						}
						if (res.data.apply.category_name == '会员住院') {
							if (res.data.apply.this_approval.name == '工会干事' && res.data.form_data.是否柳州市城区内住院 ==
								'是') {
								console.log('我是会员住院-工会干事');
								self.whether_location = 'yes'
								// 根据是否柳州市城区内住院设置慰问品选项
								self.presents = [{
									value: 0,
									text: '200元+鸡蛋+牛奶'
								}]
							} else if (res.data.apply.this_approval.name == '工会干事' && res.data.form_data.是否柳州市城区内住院 ==
								'否') {
								self.whether_location = 'yes'
								// 根据是否柳州市城区内住院设置慰问品选项
								self.presents = [{
									value: 1,
									text: '300元'
								}]
								self.formData.ps = '300元'
							} else {
								self.whether_location = null
							}
							console.log('res.data.apply', res.data.apply.status);
							// 检查是否需要发放优惠券
							
						}
						if (res.data.apply.category_name == '会员生育') {
							let category_data = res.data.apply.category_data
							console.log('category_data: ', category_data[""]);
							if (category_data[""] == '头胎') {
								self.formData.ps = '300元'
							} else {
								self.formData.ps = '400元'
							}
						}
						if (res.data.apply.category_name == '会员结婚') {
							self.formData.ps = '200元'
						}
						if (res.data.apply.category_name == '直系亲属去世') {
							self.formData.ps = '500元'
						}


						self.apply = res.data.apply
						// console.log('is_radio2: ', self.is_radio2);
						// console.log('apply: ', self.apply);
						self.form_data = res.data.form_data;
						// console.log('self.form_data: ', self.form_data);
						// self.product.content = self.adjustRichTextImageSize(self.product.content);
						// self.swiperItems[0].img = res.data.img;
						self.$refs.guipageloading.close();
						console.log(res, 'show');
					})
				} else {
					uni.showToast({
						icon: 'error',
						title: '数据错误!!'
					});
				}
			},
			//01 居中弹出
			open1: function() {
				this.$refs.guipopup1.open();
			},
			close1: function() {
				this.$refs.guipopup1.close();
			},
			//全屏签名
			open2: function() {
				this.$refs.guipopup2.open();
			},
			close2: function() {
				this.$refs.guipopup2.close();
			},
			goHome() {
				uni.reLaunch({
					url: './index'
				});
			},
			tip(type, text) {
				if (type) {
					uni.showToast({
						icon: 'success',
						title: text
					})
				} else {
					uni.showToast({
						icon: 'error',
						title: text
					})
				}
			},
			upload_img() {
				let self = this;
				if (self.formData.imgs.length >= 3) {
					self.tip_text = '慰问品领取单最多仅可上传 三 张';
					return;
				}
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: self.apiUrl + '/hzj_apply/upload_huaweicloud_obs',
							filePath: tempFilePaths[0],
							name: 'file',
							success: (up_res) => {
								let upload_res = JSON.parse(up_res.data);
								if (upload_res.code == 200) {
									uni.showToast({
										title: '上传成功',
										icon: 'none'
									});
									self.formData.imgs.push(upload_res.data.url);
								} else {
									uni.showModal({
										title: '提示',
										content: '上传失败'
									});
								}
								console.log('self.imgs: ', self.formData.imgs);
							}
						});
					}
				});
			},
			show_img(url) {
				uni.previewImage({
					urls: [url],
					index: 0
				});
			},
			dele_file_img(index) {
				this.formData.imgs.splice(index, 1);
			},
			// 检查并发放优惠券
			checkAndSendCoupon() {
				let self = this;
				// 检查process数组是否存在且不为空
				// if (self.product.process && self.product.process.length > 0) {
					// 获取最后一个审批记录
					// let lastProcess = self.product.process[self.product.process.length - 1];
					// console.log('lastProcess: ', lastProcess);
					// 检查最后一个审批记录的is_approver是否为1
					// if (lastProcess.is_approver == '1') {
						// 检查是否柳州市城区内住院字段
						let isInCity = self.form_data.是否柳州市城区内住院;
						console.log('是否柳州市城区内住院: ', isInCity);
						let hospital = self.form_data.是否进行了入院慰问;
						// 只有当是否柳州市城区内住院为"是"或"否"时才发放优惠券
						if (isInCity === '是' && hospital === '否') {
							console.log('满足发放优惠券条件，开始发放优惠券');
							
							// 调用发放优惠券的接口
							let couponData = {
								member_id: self.product.create_member,
							};
							
							let url = '/app/card_bag/apply_coupon_add';
							self.$boya.NPost(url, couponData, function(res) {
								if (res.code == 200) {
									console.log('优惠券发放成功:', res.data);
									uni.showToast({
										title: '优惠券发放成功',
										icon: 'success'
									});
								} else {
									console.log('优惠券发放失败:', res.data);
									uni.showToast({
										title: '优惠券发放失败',
										icon: 'none'
									});
								}
							}, function(error) {
								console.log('优惠券发放接口调用失败:', error);
								uni.showToast({
									title: '优惠券发放失败',
									icon: 'none'
								});
							});
						} else {
							console.log('不满足发放优惠券条件，是否柳州市城区内住院字段值不符合要求:', isInCity);
						}
					// } else {
					// 	console.log('不满足发放优惠券条件，最后一个审批记录的is_approver不为1');
					// }
				// } else {
				// 	console.log('process数组为空或不存在');
				// }
			},
		}
	}
</script>
<style scoped>
	.product-name {
		width: 560rpx;
		line-height: 50rpx;
	}

	.product-share {
		width: 80rpx;
		height: 80rpx;
		text-align: center;
		font-size: 50rpx;
		color: #FF7900;
		line-height: 80rpx;
	}

	.product-price {
		color: #FF7900;
		line-height: 60rpx;
		font-size: 30rpx;
		font-weight: bold;
	}

	.gui-common-line {
		height: 18rpx;
	}

	.product-footer {
		position: fixed;
		z-index: 99;
		left: 0;
		bottom: 0;
		width: 750rpx;
	}

	.product-attr {
		width: 700rpx;
		margin: 25rpx;
		height: 580rpx;
	}

	.html_content {
		width: 100%;
	}

	.html_content image {
		width: 100rpx;
	}

	.order_content_v {
		width: 100%;
		border-bottom: #dfdfdf solid 1rpx;
		margin: 20rpx 0;
	}

	.hx_button {
		width: 40%;
		margin: 5%;
		height: 80rpx;
		border-radius: 10rpx;
		line-height: 80rpx;
		color: #fff;
	}

	.grace-comments-face {
		height: 60rpx;
		width: 60rpx;
		border-radius: 50%;
	}

	.toubu>view {
		margin: 10rpx 0;
		font-size: 30rpx;
	}

	.qianming {
		transform: rotate(270deg);
		width: 425rpx;
		margin: -40rpx auto;
	}
</style>